package edu.ynu.se.xiecheng.achitectureclass.controller;

import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import edu.ynu.se.xiecheng.achitectureclass.dao.CustomerDao;
import edu.ynu.se.xiecheng.achitectureclass.dto.LineItemDTO;
import edu.ynu.se.xiecheng.achitectureclass.entity.Business;
import edu.ynu.se.xiecheng.achitectureclass.entity.Customer;
import edu.ynu.se.xiecheng.achitectureclass.entity.LineItem;
import edu.ynu.se.xiecheng.achitectureclass.entity.Oorder;
import edu.ynu.se.xiecheng.achitectureclass.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Api(tags = "Customer实体的控制器")
@RestController
@RequestMapping("/customer")
public class CustomerController extends LogicController<CustomerService, CustomerDao, Customer,Long> {
    public CustomerController(@Autowired CustomerService cs) {
        super(cs);
    }

    @ApiOperation("用户创建订单")
    @GetMapping("/addOrder/{customerId}/{shopId}")
    public Oorder addOrder(@PathVariable Long customerId,@PathVariable Long shopId) {
        return getService().addOorder(customerId, shopId);
    }

    @ApiOperation("用户在商店挑选商品:在特定订单中形成流水")
    @GetMapping("/selectShopItem/{customerId}/{shopId}/{orderId}/{itemId}/{quantity}")
    public LineItem selectShopItem(@PathVariable Long customerId, @PathVariable Long shopId, @PathVariable Long orderId, @PathVariable Long itemId, @PathVariable Integer quantity) {
        return getService().selectShopItem(customerId, shopId, orderId, itemId, quantity);
    }


    @ApiOperation("用户支付订单")
    @GetMapping("/payOrder/{customerId}/{orderId}")
    public Oorder payOrder(@PathVariable Long customerId, @PathVariable Long orderId) {
        return getService().pay(customerId, orderId);
    }

    @ApiOperation("用户删除未支付订单,并删除对应流水")
    @GetMapping("/deleteOrder/{orderId}")
    public void deleteOrder(@PathVariable Long orderId) {
        getService().deleteOrder(orderId);
    }

    @ApiOperation("用户注册")
    @PostMapping ("/register")
    public Customer register(@RequestParam String username, @RequestParam String password){
        return getService().register(username,password);
    }

    @ApiOperation("用户登录")
    @PostMapping ("/login")
    public Customer login(@RequestParam String username, @RequestParam String password){
        return getService().login(username,password);
    }

}